<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			
		</style>
		<script>
			onload = function(){
				var btn = document.getElementById("btn");
				btn.onclick = function(){
					ajaxAsyn("http://localhost:8080/AJAX/weibo")
					.then(function(data){
						console.log(data);
						return ajaxAsyn("http://localhost:8080/AJAX/ajaxtest");
					})
					.then(function(data){
						console.log(data);
					});
				}
			}
			
			function ajaxAsyn(url){
				return new Promise(function(success, error){
					var req = new XMLHttpRequest();
					req.open("get",url,true);
					req.onreadystatechange = function(){
						if(req.readyState==4){
							if(req.status == 200){
								success(req.responseText);
							} else {
								console.log("失败了！");
								error();
							}
						}
					}
					req.send();
				});
			}
		</script>
	</head>
	<body>
		这是一个网页，测试AJAX
		<button id="btn">请求服务器</button>
		<marquee direction="left">大王叫我来巡山</marquee>
	</body>
</html>
